//
//  wisdomQuestionView.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/11/9.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "wisdomQuestionView.h"

@interface wisdomQuestionView ()<UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;


@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableHeight;
@property (weak, nonatomic) IBOutlet UIImageView *bacImgView;

@end

@implementation wisdomQuestionView

+ (instancetype)wisdomQuestionView{
    return [[NSBundle mainBundle] loadNibNamed:@"wisdomQuestionView" owner:nil options:nil].firstObject;
}

- (void)setTitleString:(NSString *)titleString{
    titleString = titleString;
    self.titleLabel.text = [NSString stringWithFormat:@"%ld、%@", _viewTag + 1, titleString];
}

- (void)setViewTag:(NSInteger)viewTag{
    _viewTag = viewTag;
}

//-(void)setSelectNO:(NSInteger)selectNO
//{
//    
//}

- (void)setOptionArray:(NSArray *)optionArray{
    _optionArray = optionArray;
    self.tableHeight.constant = optionArray.count * 50;
    [self.tableView reloadData];
}

- (void)setImgName:(NSString *)imgName{
    _imgName = imgName;
    self.bacImgView.image = [UIImage imageNamed:imgName];
}

- (void)awakeFromNib{
    [super awakeFromNib];
    self.selectNO = -1;
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.layer.cornerRadius = 3.0;
    self.tableView.layer.borderWidth = 0.5;
    self.tableView.layer.borderColor = ZKcolor(245, 245, 245).CGColor;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _optionArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *cellID = @"cellid2";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellID];
    }
    if (self.selectNO == indexPath.row) {
        cell.textLabel.textColor = [UIColor redColor];
    }else{
        [cell.textLabel setTextColor:ZKcolor(170, 170, 170)];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSString *title = _optionArray[indexPath.row];
    cell.textLabel.text = title;
    cell.textLabel.numberOfLines = 0;
    [cell.textLabel setFont:[UIFont systemFontOfSize:13]];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.selectNO = indexPath.row;
    _isSelect = YES;
    [self.tableView reloadData];
    if ([self.delegate respondsToSelector:@selector(returnSlectOption:WithViewTag:)]) {
        [self.delegate returnSlectOption:indexPath.row WithViewTag:_viewTag];
    }
}

@end
